﻿#include "OperSubsystemSemiInfiniteFluid.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "FITK_Component/FITKAcousticsModel/FITKSEASubSysSemiInfiniteFluid.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"

#include "OperatorsInterface/GraphEventOperator.h"
#include "updateBrowserTable.h"
#include "GUIWidget/AttributeSetDialog.h"

#include <QAction>

namespace ModelOper
{
    bool OperSubsystemSemiInfiniteFluid::execGUI()
    {
        return false;
    }

    bool OperSubsystemSemiInfiniteFluid::execProfession()
    {
        return false;
    }

    void OperSubsystemSemiInfiniteFluid::editSubsystem(const int seaID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        QAction action;
        action.setObjectName("actionEditSemiInfiniteFluid");
        Core::FITKActionOperator* oper = Core::FITKOperatorRepo::getInstance()->getOperatorT<Core::FITKActionOperator>("actionEditSemiInfiniteFluid");
        if (!oper) return;
        oper->setArgs("DataID", seaID);
        oper->setEmitter(&action);
        oper->actionTriggered();
    }

    void OperSubsystemSemiInfiniteFluid::removeSubsystem(const int seaID)
    {
        //获取管理器
        if (!_seaMgr)return;
        //移除并更新列表
        _seaMgr->removeDataByID(seaID);
        ModelOper::updateBrowserTable();
        EventOper::GraphEventOperator* operGraph = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        operGraph->updateSEASubSystems();
    }

    void OperSubsystemSemiInfiniteFluid::setAttribute(const QString & name, const QString & text, const int attrIndex, const QList<int>& seaID)
    {
        if (!_seaMgr)return;
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        Acoustics::FITKAcousticsPhysics* phys = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phys == nullptr) return;
        Acoustics::FITKAcousticsMaterialManager* matMgr = phys->getMaterialManager();
        if (matMgr == nullptr) return;

        //设置对话框
        GUI::AttributeSetDialog dlg(2, mw);
        dlg.setTextLabel(name);
        QList<Acoustics::FITKAcousticsAbsMaterial*>matList = matMgr->getAcousticsMaterials(Acoustics::FITKAcousticsAbsMaterial::Fluid);
        QList<QString> list;
        for (auto value : matList) {
            list += value->getDataObjectName();
        }
        dlg.setDefaultValueQString(list);
        if (dlg.exec() != QDialog::Accepted) return;

        //材料
        QString mat = dlg.getValueQString();
        int matID = matMgr->getDataByName(mat)->getDataObjectID();

        for (int id : seaID)
        {
            Acoustics::FITKSEASubSysSemiInfiniteFluid* sem = dynamic_cast
                <Acoustics::FITKSEASubSysSemiInfiniteFluid*>(_seaMgr->getDataByID(id));
            if (sem == nullptr) continue;
            //不同列设置不同参数
            sem->setMaterialID(matID);
        }
        ModelOper::updateBrowserTable();
    }

}
